package com.xsz.repository;

import com.xsz.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

//JpaRepository<User,String>  第一个参数是实体类，第二个参数是实体类的主键数据类型
public interface UserRepository extends JpaRepository<User,String> {
	
	public User findByNameAndPwd(String name, String pwd);
	public List<User> findByNameLike(String name);
	public User findByName(String name);
	public User findByIdAndPwd(String id, String pwd);

	@Transactional
	@Modifying
	@Query("update User u set u.pwd = ?1 where u.id = ?2")
	int updatePwdById(String pwd, String id);

	@Modifying
	@Transactional
	@Query("update User set name=?1, sex=?2, mobile=?3, age=?4, email=?5 where id=?6")
	int userEdit(String name, String sex, String mobile, Integer age, String email, String id);
}
